#include "Supervisor.h"
#include "hw/board.hpp"

void Supervisor::advance_start() {
  Parent::advance_start();
  auto uart_id = get_child<0>()->get_id();
  send<rl::ctx::thread, message::LogStatic>(0, uart_id, "starting...\r\n");
  heartbeat();

  auto dht_id = get_child<1>()->get_id();
  send<rl::ctx::thread, message::RequestHT>(0, dht_id);
}

void Supervisor::heartbeat() {
  hw::Board::toggle_led();
  add_event<rl::ctx::thread>(
      1000000, [](void *) { sup.heartbeat(); }, this);
  auto uart_id = get_child<0>()->get_id();
  send<rl::ctx::thread, message::LogStatic>(0, uart_id, "heartbeat\r\n");
}
